<template>
  <div class="app-container">
    <el-form :model="searchForm" label-width="80px" @keyup.enter.native="search()">
      <el-row>
        <el-col class="professions">
          <el-form-item label="所属专业" size="small">
            <el-select v-model="searchForm.professions" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in parentProfessionList"
                :key="item.professionId"
                :label="item.professionName"
                :value="item.professionName">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="所属团队" size="small">
            <el-input v-model="searchForm.teamName"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="项目名称" size="small">
            <el-input v-model="searchForm.tenderName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item size="small">
            <el-button type="primary" icon="el-icon-search" @click="search()">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="table-btn">
      <el-button type="primary" size="small" icon="el-icon-plus" @click="addTeam()">添加</el-button>
      <el-dialog :title="dialogTitle" :visible.sync="outerVisible" width="1100px" @close="closeOuterVisible">
        <el-form ref="teamRow" :rules="rules" :model="teamRow" label-width="120px">
          <el-form-item prop="tenderName" label="项目名称" size="small">
            <el-input type="text" v-model="teamRow.tenderName" @change="tenderNameBlur"></el-input>
          </el-form-item>
          <el-form-item prop="teamName" label="所属团队" size="small" class="item-inline">
            <el-autocomplete
              v-model="teamRow.teamName"
              :fetch-suggestions="querySearchTeam"
              @select="handleSelectTeam"
              placeholder="请输入内容"
            >
            </el-autocomplete>
          </el-form-item>
          <el-form-item prop="head" label="项目负责人" size="small" class="item-inline">
            <el-input type="text" v-model="teamRow.head"></el-input>
          </el-form-item>
          <el-form-item prop="projectScale" label="项目规模" size="small" class="item-inline">
            <el-input type="text" v-model="teamRow.projectScale"></el-input>
          </el-form-item>
          <el-form-item prop="projectCost" label="项目造价" size="small" class="item-inline">
            <el-input type="number" v-model.number="teamRow.projectCost">
              <span slot="suffix">万元</span>
            </el-input>
          </el-form-item>
          <el-form-item prop="serviceFee" label="投标服务费" size="small" class="item-inline">
            <el-input type="number" v-model.number="teamRow.serviceFee">
              <span slot="suffix">元</span>
            </el-input>
          </el-form-item>
          <el-form-item prop="travelFee" label="差旅费" size="small" class="item-inline">
            <el-input type="number" v-model.number="teamRow.travelFee">
              <span slot="suffix">元</span>
            </el-input>
          </el-form-item>
          <el-form-item label="人员出场费" size="small" class="item-inline">
            <el-input type="number" v-model.number="teamRow.staffingFee">
              <span slot="suffix">元</span>
            </el-input>
          </el-form-item>
          <el-form-item prop="bidTime" label="开标日期" size="small" class="item-inline">
            <el-date-picker
              v-model="teamRow.bidTime"
              type="date"
              value-format="timestamp"
              placeholder="选择日期"
              style="width:185px;"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="投标地址" size="small" class="item-inline">
            <el-input type="text" v-model="teamRow.bidAdress"></el-input>
          </el-form-item>
          <el-form-item prop="partyA" label="甲方单位" size="small">
            <el-input type="text" v-model="teamRow.partyA"></el-input>
          </el-form-item>
          <el-form-item prop="address" label="项目所属地" size="small">
            <area-cascader v-model="teamRow.addressId" v-if="isAddress" placeholder="请选择省市" :data="pca"
                           @change="addressChange()"></area-cascader>
            <el-input type="textarea" v-model="teamRow.address" placeholder="请填写项目所属地"></el-input>
          </el-form-item>
          <el-form-item prop="bidPersions" label="开标人" size="small">
            <el-input type="textarea" v-model="teamRow.bidPersions"></el-input>
          </el-form-item>
          <el-form-item label="资料上传负责人" size="small">
            <el-input type="text" v-model="teamRow.updatePrincipal"></el-input>
          </el-form-item>
          <el-form-item prop="tenderType" label="招投标类型" size="small">
            <el-checkbox-group v-model="teamRow.tenderType"
                               @change="handleTenderTypeChange">
              <el-checkbox v-for="item in tenderTypeList" :label="item.tenderTypeName"
                           :key="item.tenderTypeName">
                {{item.tenderTypeName}}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="是否联合投标" size="small">
            <el-switch
              v-model="teamRow.isUnionBid"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value=1
              :inactive-value=0
            >
            </el-switch>
          </el-form-item>
          <el-form-item prop="unionCompany" v-if="teamRow.isUnionBid" label="联合单位" size="small">
            <el-input type="textarea" v-model="teamRow.unionCompany"></el-input>
          </el-form-item>
          <el-form-item prop="contactPerson" v-if="teamRow.isUnionBid" label="联系人" size="small">
            <el-input type="text" v-model="teamRow.contactPerson"></el-input>
          </el-form-item>
          <el-form-item prop="contact" v-if="teamRow.isUnionBid" label="联系方式" size="small">
            <el-input type="text" v-model="teamRow.contact"></el-input>
          </el-form-item>
          <el-form-item label="是否投标成功" size="small">
            <el-switch
              v-model="teamRow.isSuccessful"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value=1
              :inactive-value=0
            >
            </el-switch>
          </el-form-item>
          <el-form-item label="所属专业" size="small">
            <el-checkbox-group v-for="(profession,index) in professionList" v-model="teamRow.parentProfessions">
              <el-checkbox :label="profession.professionName" :key="profession.professionName"
              >
                {{profession.professionName}}
              </el-checkbox>
              <el-checkbox-group v-model="teamRow.childProfessions"
                                 @change="handleprofessionChange(index,profession)">
                <el-checkbox v-for="item in profession.getParent" :label="item.professionId"
                             :key="item.professionId">
                  {{item.professionName}}
                </el-checkbox>
              </el-checkbox-group>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="竞标企业" size="small">
            <el-button type="primary" icon="el-icon-plus" @click="addbidderList()"></el-button>
          </el-form-item>
          <el-row v-for="(item,index) in bidderList">
            <el-col class="other">
              <el-form-item label="投标单位" size="small">
                <el-input type="text" v-model="item.tenderUnit"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="商务报价" size="small">
                <el-input type="number" v-model.number="item.quote">
                  <span slot="suffix">万元</span>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="商务得分" size="small">
                <el-input type="number" v-model.number="item.businessScore"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="技术得分" size="small">
                <el-input type="number" v-model.number="item.technicalScore"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="资信得分" size="small">
                <el-input type="number" v-model.number="item.creditScore"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="最后得分" size="small">
                <el-input type="number" v-model.number="item.finalScore"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="其他" size="small">
                <el-input type="text" v-model="item.other"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="other">
              <el-form-item label="排名" size="small">
                <el-input type="number" v-model.number="item.ranking"></el-input>
              </el-form-item>
            </el-col>
            <el-col class="searchBtn">
              <el-form-item size="small">
                <el-button type="danger" size="small" icon="el-icon-minus" @click="delbidderList(index)"></el-button>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="备注说明" size="small">
            <el-input type="textarea" v-model="teamRow.remark"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="warning" size="small" @click="submitForm('teamRow')" v-no-more-click :disabled="isTenderName">确定</el-button>
          <el-button size="small" @click="outerVisible = false;isAddress = false">取消</el-button>
        </div>
      </el-dialog>
      <a target="_blank"
         :href="`/tenders/export?${encodeURI(exportUrl)}`">
        <el-button type="warning" size="small" icon="el-icon-upload2">
          导出
        </el-button>
      </a>
    </div>
    <my-table
      :data="tableData"
      :col-configs="colConfigs"
      v-loading="listLoading"
      :page-num="pageNum"
      :page-size="pageSize"
      :table-type="tableType"
      :expand-all="expandAll"
      @fetchData="fetchData"
    >
      <el-table-column
        slot="opt"
        fixed="right"
        label="操作"
        width="150">
        <template slot-scope="scope">
          <!--<el-button type="text" size="small" @click="editProfession(scope.row.professions)">查看专业</el-button>-->
          <!--          <el-button-->
          <!--            @click.native.prevent="editSchedule(scope.row)"-->
          <!--            type="text"-->
          <!--            size="small">-->
          <!--            文件管理-->
          <!--          </el-button>-->
          <el-button
            @click.native.prevent="editTeam(scope.row.tenderId)"
            type="text"
            size="small"
          >
            修改
          </el-button>
          <el-popover placement="top" width="160" :ref="`popover-${scope.$index}`">
            <p>确定删除这条数据吗?</p>
            <div style="text-align: right; schedule: 0">
              <el-button size="mini" type="text" @click="$refs[`popover-${scope.$index}`].doClose()">取消</el-button>
              <el-button type="primary" size="mini" @click.native.prevent="deleteRow(scope)">确定</el-button>
            </div>
            <el-button type="text" size="small" slot="reference" v-popover:popover-${scope.$index}>删除
            </el-button>
          </el-popover>
        </template>
      </el-table-column>
    </my-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <el-dialog :title="scheduleTitle" :visible.sync="scheduleVisible" width="600px">
      <el-form ref="schedule" :rules="scheduleRules" :model="schedule" label-width="100px" class="formBorder">
        <el-form-item prop="tenderName" label="项目名称" size="small">
          <el-input type="text" v-model="schedule.tenderName" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item prop="fileName" label="文件名称" size="small">
          <el-input type="text" v-model="schedule.fileName"></el-input>
        </el-form-item>
        <el-form-item prop="typeId" label="文件类型" size="small">
          <el-select v-model="schedule.typeId" placeholder="请选择" @change="typeChange">
            <el-option
              v-for="item in infoTypeList"
              :key="item.typeId"
              :label="item.typeName"
              :value="item.typeId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="文件上传" size="small">
          <input type="file" ref='infoFile' @change="getInfoFile($event)">
        </el-form-item>
        <el-form-item size="small">
          <el-button type="warning" size="small" @click="submitSchedule('schedule',scheduleType)">
            {{scheduleBtn}}
          </el-button>
        </el-form-item>
      </el-form>
      <el-form :model="dialogForm" label-width="80px">
        <el-row>
          <el-col class="other">
            <el-form-item prop="fileTypeId" label="文件类型" size="small">
              <el-select v-model="dialogForm.fileTypeId" placeholder="请选择">
                <el-option value="" label="全部"></el-option>
                <el-option
                  v-for="item in infoTypeList"
                  :key="item.typeId"
                  :label="item.typeName"
                  :value="item.typeId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col class="searchBtn">
            <el-form-item size="small">
              <el-button type="primary" icon="el-icon-search" @click="searchDialogForm()">搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <my-table
        :data="scheduleData"
        :col-configs="scheduleConfigs"
        v-loading="scheduleLoading"
        :height="200"
      >
        <el-table-column
          slot="scheduleOpt"
          fixed="right"
          label="操作"
          width="150">
          <template slot-scope="scope">
            <a v-if="scope.row.filePath" target="_blank" :href="GLOBAL.filePathUrl+encodeURI(scope.row.filePath)">下载</a>
            <el-button
              @click.native.prevent="selectSchedule(scope.row.fileId)"
              type="text"
              size="small">
              修改
            </el-button>
            <el-popover
              placement="top"
              width="160"
              :ref="`schedule-${scope.$index}`"
            >
              <p>确定删除这条数据吗?</p>
              <div style="text-align: right; schedule: 0">
                <el-button size="mini" type="text" @click="$refs[`schedule-${scope.$index}`].doClose()">取消</el-button>
                <el-button type="primary" size="mini" @click.native.prevent="deleteSchedule(scope)">确定</el-button>
              </div>
              <el-button type="text" size="small" slot="reference" v-popover:schedule-${scope.$index}>删除</el-button>
            </el-popover>
          </template>
        </el-table-column>
      </my-table>
    </el-dialog>
    <el-dialog title="所属专业" :visible.sync="professionVisible" width="1100px">
      <el-form>
        <el-form-item size="small">
          <el-checkbox-group v-for="(profession,index) in professionList" v-model="teamRow.parentProfessions">
            <el-checkbox :label="profession.professionName" :key="profession.professionName"
            >
              {{profession.professionName}}
            </el-checkbox>
            <el-checkbox-group v-model="teamRow.childProfessions"
                               @change="handleprofessionChange(index,profession)">
              <el-checkbox v-for="item in profession.getParent" :label="item.professionId"
                           :key="item.professionId">
                {{item.professionName}}
              </el-checkbox>
            </el-checkbox-group>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import {
    addTenderFile,
    addTenderInfo,
    findInfoById,
    findTenderFilesById,
    getListTender,
    getListTenderFile,
    getParentProfessionList,
    getTypeByUseType,
    selectProfessions,
    selectTeam,
    updateTender,
    delTender,
    updateTenderFile,
    isTender
  } from '@/api/biddingproject1'
  import myTable from '@/components/myTable-biddingproject'

  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'
  import { formatDate } from '@/utils/index'
  import { isvalidPhone } from '@/utils/validate'

  const bidTime = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd')
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const isUnionBid = function(row, column) {
    return row.isUnionBid ? '是' : '否'
  }

  const isSuccessful = function(row, column) {
    return row.isSuccessful ? '是' : '否'
  }

  const professions = function(row, column) {
    return row.professions.split('-')[0]
  }

  const configs = {
    props: ['colConfig'],
    data() {
      return {
        tenderId: '',
        prop: '',
        precent: 0,
        progress: ''
      }
    },
    methods: {
      downloadFile(row, prop, column) {
        this.row = row
        this.column = column
        this.tenderId = row.tenderId
        this.prop = prop
        this.$refs.file.click()
      },
      upLoad(upLoad, params, callback1, callback2) {
        upLoad(params, function(progressEvent) { // 原生获取上传进度的事件
          if (progressEvent.lengthComputable) {
            // 属性lengthComputable主要表明总共需要完成的工作量和已经完成的工作是否可以被测量
            // 如果lengthComputable为false，就获取不到progressEvent.total和progressEvent.loaded
            callback1(progressEvent)
          }
        }).then(res => {
          callback2(res.data)
        }).catch(() => {
          this.$refs.file.value = ''
          this.progress = ''
        })
      },
      fileChanged() {
        const _this = this
        _this.progress = `${_this.row.tenderId}${_this.column.id}`
        _this.precent = 0
        const params = new FormData()
        params.append('tenderId', this.tenderId)
        if (this.prop === 'tenderFile') {
          params.append('file', this.$refs.file.files[0])
        } else {
          params.append(`${this.prop}File`, this.$refs.file.files[0])
        }
        _this.upLoad(updateTender, params, (res) => {
          const loaded = res.loaded
          const total = res.total
          _this.$nextTick(() => {
            _this.precent = (loaded / total) * 100
          })
        }, (res) => {
          _this.$refs.file.value = ''
          _this.progress = ''
          _this.$emit('fetchData')
        })
      }
    },
    template: `
  <el-table-column :label="colConfig.label">
            <input class="file" type="file" @change="fileChanged" ref="file"/>
            <el-table-column  v-for="(item, index) in colConfig.children"  :label="item.label" :width="item.width">
                <span slot-scope="scope" >
                    <span v-if="item.component==='filePath'">
                        <div v-if="scope.row[item.prop]">
                            <a @click="downloadFile(scope.row,item.prop,scope.column)">上传</a>
                            <a target="_blank" :href="GLOBAL.filePathUrl+ encodeURI(scope.row[item.prop])">下载</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.tenderId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                        <div v-else>
                            <a style="color: red" >X</a>
                            <a @click="downloadFile(scope.row,item.prop,scope.column)">上传</a>
                            <el-progress :text-inside="true" :stroke-width="15" v-if="progress===(scope.row.tenderId+scope.column.id)" :percentage="precent" status="success"></el-progress>
                        </div>
                    </span>
                </span>
            </el-table-column>
  </el-table-column>
  `
  }

  export default {
    components: {
      myTable,
      AreaSelect
    },
    data() {
      const validPhone = (rule, value, callback) => {
        if (!value) {
          callback()
        } else if (!isvalidPhone(value)) {
          callback(new Error('请输入正确的11位手机号码'))
        } else {
          callback()
        }
      }
      return {
        colConfigs: [
          { prop: 'tenderName', label: '项目名称', width: '230', fixed: true },
          { prop: 'professions', label: '所属专业', width: '160', formatter: professions },
          { prop: 'bidTime', label: '开标时间', width: '100', component: bidTime },
          { prop: 'bidAdress', label: '投标地址', width: '200' },
          { prop: 'partyA', label: '甲方单位', width: '200' },
          { prop: 'teamName', label: '所属团队', width: '100' },
          { prop: 'tenderType', label: '招投标类型', width: '150' },
          { prop: 'head', label: '项目负责人', width: '100' },
          { prop: 'projectScale', label: '项目规模', width: '80' },
          { prop: 'bidPersions', label: '开标人', width: '100' },
          { prop: 'updatePrincipal', label: '资料上传负责人', width: '110' },
          { prop: 'projectCost', label: '项目造价(万元)', width: '100' },
          { prop: 'serviceFee', label: '投标服务费(元)', width: '100' },
          { prop: 'travelFee', label: '差旅费(元)', width: '100' },
          { prop: 'staffingFee', label: '人员出场费(元)', width: '100' },
          { prop: 'address', label: '项目所属地', width: '150' },
          { prop: 'isUnionBid', label: '是否联合投标', width: '100', formatter: isUnionBid },
          { prop: 'unionCompany', label: '联合单位', width: '250' },
          { prop: 'isSuccessful', label: '是否投标成功', width: '100', formatter: isSuccessful },
          {
            label: '招标', children: [
              { prop: 'tenderFile', label: '招标文件', width: '100', component: 'filePath' },
              { prop: 'tenderBook', label: '标书', width: '100', component: 'filePath' }
            ], component: configs
          },
          {
            label: '方案', children: [
              { prop: 'programText', label: '方案文本', width: '100', component: 'filePath' },
              { prop: 'programRendering', label: '方案效果图', width: '100', component: 'filePath' }
            ], component: configs
          },
          { slot: 'opt' }
        ],
        scheduleConfigs: [
          { prop: 'fileName', label: '文件名称', width: '200' },
          { prop: 'fileType', label: '文件类型', width: '150' },
          { slot: 'scheduleOpt' }
        ],
        searchForm: {},
        dialogForm: {},
        searchFormList: {},
        dialogFormList: {},
        infoTypeList: [],
        parentProfessionList: [],
        professionList: [],
        parentList: [],
        listLoading: true,
        scheduleLoading: true,
        dialogTitle: '新增招投标项目',
        scheduleTitle: '项目资料管理',
        scheduleType: 1,
        scheduleBtn: '添加资料',
        dialogType: 0,
        teamRow: {
          childProfessions: [],
          parentProfessions: [],
          tenderType: []
        },
        teamRowClear: {},
        schedule: {},
        scheduleClear: {},
        tableData: [],
        scheduleData: [],
        pageNum: 1,
        pageSize: 10,
        total: 1,
        outerVisible: false,
        scheduleVisible: false,
        professionVisible: false,
        isAddress: false, // 地区新增 修改 摧毁 生成组件
        isRender: false, // 判断地区是否编辑
        pca: pca,
        rules: {
          tenderName: [
            { required: true, message: '请输入项目名称', trigger: 'change' }
          ],
          teamName: [
            { required: true, message: '请输入团队', trigger: 'change' }
          ],
          head: [
            { required: true, message: '请输入项目负责人', trigger: 'change' }
          ],
          projectScale: [
            { required: true, message: '请输入项目规模', trigger: 'change' }
          ],
          tenderType: [
            { required: true, message: '请选择招投标类型', trigger: 'change' }
          ],
          staffingFee: [
            { required: true, message: '请输入人员出场费', trigger: 'change' }
          ],
          bidTime: [
            { required: true, message: '请选择开标时间', trigger: 'change' }
          ],
          partyA: [
            { required: true, message: '请输入甲方单位', trigger: 'change' }
          ],
          address: [
            { required: true, message: '请输入项目所属地', trigger: 'change' }
          ],
          unionCompany: [
            { required: true, message: '请输入联合单位', trigger: 'change' }
          ],
          contactPerson: [
            { required: true, message: '请输入联合单位联系人', trigger: 'change' }
          ],
          contact: [
            { required: true, trigger: 'change', validator: validPhone }
          ],
          professions: [
            { required: true, message: '请选择所属专业', trigger: 'change' }
          ]
        },
        scheduleRules: {
          tenderName: [
            { required: true, message: '请输入项目名称', trigger: 'change' }
          ],
          fileName: [
            { required: true, message: '请输入文件名称', trigger: 'change' }
          ],
          fileTypeId: [
            { required: true, message: '请选择资料类型', trigger: 'change' }
          ]
        },
        tenderTypeList: [
          { tenderTypeName: '商务' },
          { tenderTypeName: '资信' },
          { tenderTypeName: '技术' }
        ],
        visible: false,
        isTenderName: false, // // 判断是否有招投标项目
        exportUrl: '', // 导出参数
        tableType: true,
        expandAll: false, // 表格展开折叠
        bidderList: []
      }
    },
    created() {
      this.teamRowClear = JSON.parse(JSON.stringify(this.teamRow))
      this.fetchData()
      this.getParentProfessionList()
      this.getListProfession()
      this.getTypeByUseType()
    },
    computed: {
      teamId() {
        return this.$store.state.user.teamId
      },
      isDirector() {
        return this.$store.state.user.isDirector
      }
    },
    methods: {
      fetchData() {
        this.searchFormList.pageNum = this.pageNum
        this.searchFormList.pageSize = this.pageSize
        // this.searchFormList.isDirector = this.isDirector
        // this.searchFormList.teamId = this.teamId
        this.listLoading = true
        getListTender(this.searchFormList).then(response => {
          this.tableData = response.responseBody.list
          this.total = response.responseBody.total
          this.listLoading = false
        })
      },
      getParentProfessionList() {
        getParentProfessionList().then(response => {
          this.parentProfessionList = response.responseBody
        })
      },
      getListProfession() {
        selectProfessions().then(response => {
          const that = this
          this.professionList = response.responseBody
          this.professionList.forEach(function(value, index, array) {
            that.parentList[index] = []
            value.getParent.forEach(function(value) {
              that.parentList[index].push(value.professionId)
            })
          })
        })
      },
      scheduleFetchData() {
        this.scheduleLoading = true
        this.dialogFormList.tenderId = this.schedule.tenderId
        getListTenderFile(this.dialogFormList).then(response => {
          this.scheduleData = response.responseBody
          this.scheduleLoading = false
        })
      },
      getTypeByUseType() {
        const params = {
          useType: 2
        }
        getTypeByUseType(params).then(response => {
          this.infoTypeList = response.responseBody
        })
      },
      provinceChange() {
        this.searchForm.cityId = ''
        console.log(this.pca[86])
      },
      cityChange() {
        console.log(this.pca[this.searchForm.provinceId])
      },
      search() {
        this.pageNum = 1
        this.searchFormList = JSON.parse(JSON.stringify(this.searchForm))
        this.fetchData()
      },
      searchDialogForm() {
        this.dialogFormList = JSON.parse(JSON.stringify(this.dialogForm))
        this.scheduleFetchData()
      },
      addTeam() {
        this.outerVisible = true
        this.isAddress = true
        this.isTenderName = false
        this.dialogTitle = '新增招投标项目'
        this.teamRow = JSON.parse(JSON.stringify(this.teamRowClear))
        if (this.$refs['teamRow']) {
          this.$refs['teamRow'].resetFields()
        }
        this.dialogType = 1
        if (this.$refs.contractFile) {
          this.$refs.contractFile.value = ''
        }
        this.bidderList = []
      },
      editTeam(tenderId) {
        if (this.$refs['teamRow']) {
          this.$refs['teamRow'].resetFields()
        }
        this.outerVisible = true
        this.isAddress = true
        this.isRender = true
        this.isTenderName = false
        this.dialogTitle = '修改招投标项目'
        this.dialogType = 0
        this.bidderList = []
        if (this.$refs.contractFile) {
          this.$refs.contractFile.value = ''
        }
        this.teamRow = JSON.parse(JSON.stringify(this.teamRowClear))
        const params = {
          tenderId: tenderId
        }
        findInfoById(params).then(response => {
          const data = response.responseBody
          this.teamRow = Object.assign({}, this.teamRow, data)
          if (data.professions === '-') {
            this.teamRow.parentProfessions = []
            this.teamRow.childProfessions = []
          } else {
            const professions = data.professions.split('-')
            this.teamRow.parentProfessions = professions[0].split(',')
            const childProfessions = professions[1].split(',')
            childProfessions.forEach(value => {
              this.teamRow.childProfessions.push(parseInt(value))
            })
          }
          this.teamRow.addressId = [this.teamRow.provinceId.toString(), this.teamRow.cityId.toString()]
          this.teamRow.address = this.teamRow.address
          this.teamRow.tenderType = this.teamRow.tenderType.split(',')
          this.bidderList = [...this.teamRow.bidders]
        })
      },
      closeOuterVisible() {
        this.isAddress = false
      },
      submitForm(formName) {
        const tenderType = this.teamRow.tenderType.join(',')
        console.log(this.teamRow.parentProfessions)
        console.log(this.teamRow.childProfessions)
        const professions = this.teamRow.parentProfessions.join(',') + '-' + this.teamRow.childProfessions.join(',')
        console.log(professions)
        const params = new FormData()
        params.append('tenderName', this.teamRow.tenderName)
        params.append('teamId', this.teamRow.teamId)
        params.append('head', this.teamRow.head)
        params.append('projectScale', this.teamRow.projectScale)
        params.append('projectCost', this.teamRow.projectCost || 0)
        params.append('serviceFee', this.teamRow.serviceFee || 0)
        params.append('travelFee', this.teamRow.travelFee || 0)
        params.append('staffingFee', this.teamRow.staffingFee || 0)
        if (this.teamRow.bidTime) {
          params.append('bidTime', this.teamRow.bidTime)
        }
        params.append('bidAdress', this.teamRow.bidAdress || '')
        params.append('partyA', this.teamRow.partyA || '')
        params.append('provinceId', this.teamRow.provinceId)
        params.append('cityId', this.teamRow.cityId)
        params.append('address', this.teamRow.address || '')
        params.append('bidPersions', this.teamRow.bidPersions || '')
        params.append('updatePrincipal', this.teamRow.updatePrincipal || '')
        params.append('isUnionBid', this.teamRow.isUnionBid || 0)
        params.append('isSuccessful', this.teamRow.isSuccessful || 0)
        params.append('remark', this.teamRow.remark || '')
        params.append('tenderType', tenderType)
        params.append('professions', professions)
        params.append('bidderList', JSON.stringify(this.bidderList))
        if (this.teamRow.file) {
          params.append('file', this.teamRow.file)
        }
        if (this.teamRow.tenderBookFile) {
          params.append('tenderBookFile', this.teamRow.tenderBookFile)
        }
        if (!this.dialogType) {
          params.append('tenderId', this.teamRow.tenderId)
        }
        if (this.teamRow.isUnionBid) {
          params.append('unionCompany', this.teamRow.unionCompany)
          params.append('contactPerson', this.teamRow.contactPerson)
          params.append('contact', this.teamRow.contact)
        }
        if (this.teamRow.teamId) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              if (this.dialogType) {
                addTenderInfo(params).then(response => {
                  console.log(response)
                  this.outerVisible = false
                  this.isAddress = false
                  this.fetchData()
                })
              } else {
                updateTender(params).then(response => {
                  console.log(response)
                  this.outerVisible = false
                  this.isAddress = false
                  this.fetchData()
                })
              }
            } else {
              console.log('error submit!!')
              return false
            }
          })
        } else {
          this.$message({
            message: '该团队不存在',
            type: 'warning'
          })
        }
      },
      deleteRow(scope) {
        this.$refs[`popover-${scope.$index}`].doClose()
        const params = new FormData()
        params.append('tenderId', scope.row.tenderId)
        params.append('isDel', 1)
        delTender(params).then(response => {
          this.fetchData()
        })
      },
      editSchedule(row) {
        this.scheduleVisible = true
        this.scheduleClear.tenderId = row.tenderId
        this.scheduleClear.tenderName = row.tenderName
        this.schedule = JSON.parse(JSON.stringify(this.scheduleClear))
        this.scheduleFetchData()
        if (this.$refs['schedule']) {
          this.$refs['schedule'].resetFields()
        }
        this.scheduleType = 1
        this.scheduleBtn = '添加文件'
        if (this.$refs.infoFile) {
          this.$refs.infoFile.value = ''
        }
      },
      selectSchedule(fileId) {
        this.scheduleType = 0
        this.scheduleBtn = '保存文件'
        const prarms = {
          fileId: fileId
        }
        findTenderFilesById(prarms).then(response => {
          this.schedule = response.responseBody
          this.schedule.typeId = parseInt(this.schedule.fileTypeId)
        })
      },
      submitSchedule(scheduleName, type) {
        const params = new FormData()
        if (!type) {
          params.append('fileId', this.schedule.fileId)
        }
        params.append('tenderId', this.schedule.tenderId)
        params.append('fileName', this.schedule.fileName)
        params.append('fileTypeId', this.schedule.typeId)
        params.append('fileType', this.schedule.fileType)

        if (this.schedule.file) {
          params.append('file', this.schedule.file)
        }
        this.$refs[scheduleName].validate((valid) => {
          if (valid) {
            if (type) {
              addTenderFile(params).then(response => {
                this.scheduleFetchData()
                this.schedule = JSON.parse(JSON.stringify(this.scheduleClear))
                if (this.$refs.infoFile) {
                  this.$refs.infoFile.value = ''
                }
              })
            } else {
              updateTenderFile(params).then(response => {
                this.scheduleFetchData()
                this.schedule = JSON.parse(JSON.stringify(this.scheduleClear))
                this.scheduleType = 1
                this.scheduleBtn = '添加文件'
                if (this.$refs.infoFile) {
                  this.$refs.infoFile.value = ''
                }
              })
            }
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      deleteSchedule(scope) {
        this.$refs[`schedule-${scope.$index}`].doClose()
        const params = new FormData()
        console.log(scope)
        params.append('fileId', scope.row.fileId)
        params.append('isDel', 1)
        updateTenderFile(params).then(response => {
          this.scheduleFetchData()
        })
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.fetchData()
      },
      addressChange() {
        this.teamRow.provinceId = parseInt(this.teamRow.addressId[0])
        this.teamRow.cityId = parseInt(this.teamRow.addressId[1])
        if (!this.isRender) {
          this.teamRow.address = this.pca[86][this.teamRow.addressId[0]] + this.pca[this.teamRow.addressId[0]][this.teamRow.addressId[1]]
        } else {
          this.isRender = false
        }
      },
      handleTenderTypeChange(value) {
        console.log(value)
      },
      handleprofessionChange(index, profession) {
        const that = this
        const parentList = that.parentList[index]
        let isIndex = 1
        console.log(parentList)
        for (let i = 0; i < parentList.length; i++) {
          if (that.teamRow.childProfessions.indexOf(parentList[i]) !== -1) {
            isIndex = 1
            break
          } else {
            isIndex = 0
          }
        }
        if (isIndex) {
          that.teamRow.parentProfessions.push(profession.professionName)
          that.teamRow.parentProfessions = [...new Set(that.teamRow.parentProfessions)]
        } else {
          that.teamRow.parentProfessions.splice(that.teamRow.parentProfessions.findIndex(item => item === profession.professionName), 1)
        }
      },
      querySearchProject(queryString, callback) {
        // queryString 为在框中输入的值
        // callback 回调函数,将处理好的数据推回
        const params = {
          projectName: queryString
        }
        selectTeam(params).then(response => {
          for (const i of response.responseBody) {
            i.value = i.projectName
          }
          let teamList = response.responseBody
          if (teamList.length === 0) {
            teamList = [{ value: '暂无数据' }]
          }
          callback(teamList)
        })
      },
      handleSelectProject(item) {
        this.$set(this.teamRow, 'projectId', item.projectId)
      },
      querySearchTeam(queryString, callback) {
        // queryString 为在框中输入的值
        // callback 回调函数,将处理好的数据推回
        delete this.teamRow.teamId
        const params = {
          teamName: queryString
        }
        selectTeam(params).then(response => {
          for (const i of response.responseBody) {
            i.value = i.teamName
          }
          let nameList = response.responseBody
          if (nameList.length === 0) {
            nameList = [{ value: '暂无数据' }]
          }
          callback(nameList)
        })
      },
      handleSelectTeam(item) {
        this.$set(this.teamRow, 'teamId', item.teamId)
      },
      getFile(event) {
        this.teamRow.file = event.target.files[0]
        console.log(this.teamRow)
      },
      getInfoFile(event) {
        this.schedule.file = event.target.files[0]
      },
      editProfession(professions) {
        const that = this
        this.professionVisible = true
        this.teamRow.parentProfessions = []
        this.teamRow.childProfessions = []
        this.teamRow.parentProfessions = professions.split('-')[0].split(',')
        const childProfessions = professions.split('-')[1].split(',')
        childProfessions.forEach(function(value) {
          that.teamRow.childProfessions.push(parseInt(value))
        })
      },
      typeChange(value) {
        this.infoTypeList.forEach((val) => {
          if (val.typeId === value) {
            this.schedule.fileType = val.typeName
          }
        })
      },
      tenderNameBlur() {
        if (this.dialogType === 1) {
          const params = {
            tenderName: this.teamRow.tenderName
          }
          isTender(params).then(response => {
            if (response.resultCode === 1) {
              this.isTenderName = false
            } else {
              this.isTenderName = true
            }
          })
        }
      },
      addbidderList() {
        this.bidderList.push({
          tenderUnit: '',
          quote: 0,
          businessScore: 0,
          technicalScore: 0,
          creditScore: 0,
          finalScore: 0,
          other: '',
          ranking: ''
        })
      },
      delbidderList(index) {
        this.bidderList.splice(index, 1)
      }
    },
    mounted() {

    },
    watch: {
      'searchForm': {
        handler(newValue, oldValue) {
          let exportUrl = ''
          Object.keys(this.searchForm).map((key) => {
            exportUrl += key + '=' + this.searchForm[key] + '&'
          })
          this.exportUrl = exportUrl
        },
        immediate: true,
        deep: true // 深度监听
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss">
  .app-container {
    .el-pagination {
      margin-top: 20px;
    }

    .table-btn {
      margin-bottom: 10px;

      & > button {
        margin: 0 20px;
      }

      .el-dialog {
        textarea {
          margin-top: 10px;
        }

        .el-checkbox {
          margin-right: 20px;
        }

        .el-checkbox + .el-checkbox {
          margin-left: 0;
        }

        .item-inline {
          display: inline-block;
        }
      }
    }
  }
</style>


<style rel="stylesheet/scss" lang="scss">
  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  .el-input--suffix .el-input__inner {
    padding-right: 15px;
  }

  a, a:focus, a:hover {
    color: #409EFF;
  }

  /*.el-table__body tr.hover-row>td {
    background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
    background-color: #0000ff !important;
  }*/
</style>
